
package uk.org.cardboardbox.nfcpointstracker.model;

import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Tag {

    private static final String TAG = Tag.class.getCanonicalName();

    private int version;

    private String serial;

    private String owner;

    private int points;

    private byte[] photo;

    public Tag(String serial, String owner) {
        this.serial = serial;
        this.owner = owner;

    }

    public static final Tag fromNDEFMessage(NdefMessage message) {
        NdefRecord[] records = message.getRecords();
        for (NdefRecord r : records) {
            Log.d(TAG, new String(r.getPayload()));
        }

        Tag tag = new Tag("123", "Dave");
        return tag;
    }

    public String getOwner() {
        return owner;
    }

    public void subPoints(int points) {
        points -= points;
    }

    public void addPoints(int points) {
        points += points;
    }

    public int getPoints() {
        return points;
    }

    public void setPhotoFromFile(File source) {
        try {
            photo = new byte[(int)source.length()];
            FileInputStream fis = new FileInputStream(source);
            fis.read(photo);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public byte[] getPhoto() {
        return photo;
    }

}
